#pragma once
#ifndef xIApp_h__
#define xIApp_h__

#include "../../../dxhead/dxegheader.h"
#include "../../../xlib/xlib.h"
namespace NTools
{
	class xD3DEnv;
	class xDevice;
	class xWindow;
	struct xState;

	typedef enum _ExitCode{
		ExitCode_Success,
		ExitCode_Exit,
		ExitCode_Failed,
		ExitCode_ComLost,
		ExitCode_ResLost,
		ExitCode_AccDenied,
		ExitCode_Unknow
	}ExitCode;

	class xDxApp
	{
	public:
		/*DXAPI xApp(TVoid);
		DXAPI ~xApp(TVoid);*/

	public:
		virtual const TChar*	getAppName() = 0;
		virtual xD3DEnv*	getD3DEnv() = 0;
		virtual xWindow*	getWindow() = 0;
		virtual xDevice*	getDevice() = 0;
		virtual xState*     getState() = 0;

	public:
		//------------------------------------------------------------------------------------
		//Create the 3d environment
		//------------------------------------------------------------------------------------
		virtual TResult Create3DEnv()=0;
		//------------------------------------------------------------------------------------
		//Create the main window,then use Create3DDevice()
		//------------------------------------------------------------------------------------

		virtual TResult Create3DWindow(const TChar* strWindowTitle = L"dxeg",
			TUint dwWinStyle=WS_POPUP,
			TInt nDefaultX=0,TInt nDefaultY=0,TInt nDefaultWidth=1024,TInt nDefaultHeight=768,
			WNDPROC wndProc=vNull/*if vNull,use default*/) = 0;
		//------------------------------------------------------------------------------------
		//Set the window that will be rendered,then use Create3DDevice()
		//------------------------------------------------------------------------------------
		virtual TResult Set3DWindow(HWND hWnd,TBool handlemsg=VFalse) = 0;
		//------------------------------------------------------------------------------------
		//Create the device,then use Main loop()
		//------------------------------------------------------------------------------------
		virtual TResult Create3DDevice(UINT AdapterOrdina=D3DADAPTER_DEFAULT, TBool bWindowed=VTrue,
			TInt nSuggestedBufferWidth=1024, TInt nSuggestedBufferHeight=768) = 0;
		//------------------------------------------------------------------------------------
		//The message loop
		//------------------------------------------------------------------------------------
		virtual TResult MainLoop(TBool bWinProc = VFalse,TBool need3D = VFalse) = 0;
		//------------------------------------------------------------------------------------
		//Get the exit code
		//------------------------------------------------------------------------------------
		virtual TInt		GetExitCode() = 0;
		//------------------------------------------------------------------------------------
		//Set the exit code
		//------------------------------------------------------------------------------------
		virtual TVoid	SetExitCode(ExitCode code) = 0;
		//------------------------------------------------------------------------------------
		//Set the TResult code
		//------------------------------------------------------------------------------------
		virtual TVoid SetResult(TInt hr) = 0;
		//------------------------------------------------------------------------------------
		//Set the TResult code
		//------------------------------------------------------------------------------------
		virtual TResult GetResult() = 0;
		//------------------------------------------------------------------------------------
		//Set the TResult code
		//------------------------------------------------------------------------------------
		virtual TVoid	ShowWindow(TBool bShow = VTrue) = 0;
	public:
		//------------------------------------------------------------------------------------
		//Called to rendered object
		//in XApp::OnRenderSceneLoop(),Objects added called OnRenderSceneLoop() function
		//------------------------------------------------------------------------------------
		virtual TResult	RenderSceneLoop() = 0;
		//------------------------------------------------------------------------------------
		//Called to handle message
		//in XApp::OnHandlerMessageLoop(),Objects added called OnHandlerMessageLoop() function
		//------------------------------------------------------------------------------------
		virtual TResult	HandleMessageLoop() = 0;
		//------------------------------------------------------------------------------------
		//Called to handle message
		//in XApp::HandleWinPorc(),Objects added called HandleWinPorc() function
		//------------------------------------------------------------------------------------
		virtual TResult	HandleWinPorc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) = 0;
	protected:
		virtual TResult onDeviceCreate(xDevice* pDevice) = 0;
		virtual TResult	onDeviceDestroy() = 0;
		virtual TResult	onDeviceReset(xDevice* pDevice) = 0;
		virtual TResult	onDeviceLost() = 0;
		virtual TResult onChangeSettings(xDevice* pDevice) = 0;

	public:
		//------------------------------------------------------------------------------------
		//Called when having a  message
		//------------------------------------------------------------------------------------
		//virtual TVoid    OnMessage(xEventMessage* pMsgInfo);
		//------------------------------------------------------------------------------------
		//Force the engine to exit,and release pd3ddevice
		//------------------------------------------------------------------------------------
		virtual TVoid	Shutdown(ExitCode code = ExitCode_Exit) = 0;
		//------------------------------------------------------------------------------------
		//use positive number to increase the times paused,
		//and negative number to decrease the times paused
		//------------------------------------------------------------------------------------
		virtual TVoid	AddPauseCount(TInt PauseTimeCount=0,TInt PauseRenderCount=0) = 0;
		//
		virtual ExitCode Exit() = 0;
	//public:
	//	//------------------------------------------------------------------------------------	
	//	//Create device ,XIObjects are created automatically
	//	//------------------------------------------------------------------------------------	
	//	virtual TResult	Create3DObjects() = 0; 
	//	//------------------------------------------------------------------------------------
	//	//Reset device ,XIObjects reseted automatically
	//	//------------------------------------------------------------------------------------
	//	virtual TResult	Reset3DObjects() = 0;
	//	//------------------------------------------------------------------------------------
	//	//Handle Timer and Device state, XIObjects rendered automatically
	//	//------------------------------------------------------------------------------------
	//	virtual TVoid	Render3DObjects() = 0; 
	//	//------------------------------------------------------------------------------------
	//	//Release Device , XIObjects lost and destroy automatically
	//	//------------------------------------------------------------------------------------
	//	virtual TResult	Clear3DObjects() = 0;	
	};
}

#endif // xIApp_h__